#!/bin/bash
targetdir=/opt/jgzentao
logfile=$targetdir/log/jgzentao_`date +"%F"`.txt
/usr/local/mysql/bin/mysql -u jgztao -pK6kBICTM zentao -h 192.168.0.44 -e"select * from ( select assignedTo as name , status, count(*) from zt_bug where openedBuild = 20 and  status ='active' group by assignedTo, status union select resolvedBy as name ,status, count(*) from zt_bug where openedBuild = 20 and  status !='active'  group by resolvedBy, status ) a order by name\G ;"|grep -v ".row" >$logfile

sendmail() {
##sendmail~~
date=`date +%F`
if [ -f "$targetdir/tosendlist.txt" ] && [ -f "$targetdir/mail.jar" ];then
    for toSend in `cat $targetdir/tosendlist.txt`
        do
            java -jar $targetdir/mail.jar -to "$toSend" -sub "Jingoal-ZentaoReport-$date" -file "$logfile"
        done
else
    echo "Download needed files error" && exit 1
fi
echo 'send end!'
}
JAVA_HOME=/usr/local/jdk
PATH=$JAVA_HOME/bin:$PATH
export JAVA_HOME PATH
sendmail
